<?php
class profile_ProfileMapper
{
	
	public function __construct()
	{
		$this->profileTable = new tables_ProfileTable();
	}
	
	public function findByUser(user_User $user)
	{
		$profile_info = $this->profileTable->fetchRow('user_id = '.$user->userId );
		$profile = new profile_Profile();
		$profile->setId($profile_info->id);
		$profile->setNickname($profile_info->nickname);
		$profile->setUserId($profile_info->user_id);
		return $profile;
	}
	
	public function save(profile_Profile $profile)
	{
		$data = array('nickname' => $profile->getNickname());
		$where = $this->profileTable->getAdapter()->quoteInto('id = ?', $profile->getId());
		return $this->profileTable->update($data, $where);
	}
	
	
	/**
	 * create a new profile in the database
	 *
	 * @param profile_Profile $profile
	 * @return unknown
	 */
	public function create(profile_Profile $profile)
	{
		$table = new tables_ProfileTable();
		$row = $table->createRow();
		$row->user_id = $profile->getUserId();
		$row->nickname = $profile->getNickname();
		return $row->save();
	}
	
}
?>